package com.sea.service.impl;

import com.sea.mapper.CategoryMapper;
import com.sea.pojo.Category;
import com.sea.service.CategoryService;
import com.sea.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper cm;

    @Override
    public void add(Category cg) {
        cg.setCreateTime(LocalDateTime.now());
        cg.setUpdateTime(LocalDateTime.now());
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        cg.setCreateUser(id);
        cm.add(cg);
    }

    @Override
    public List<Category> getl() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer uid = (Integer) map.get("id");
        return cm.getl(uid);
    }

    @Override
    public Category findById(Integer id) {
        return cm.findById(id);
    }

    @Override
    public void updateC(Category cg) {
        cg.setUpdateTime(LocalDateTime.now());
        cm.updateC(cg);
    }

    @Override
    public void delete(Integer id) {
        cm.delete(id);
    }
}
